
package com.liao.badminton.controller;

import cn.hutool.db.PageResult;
import com.github.pagehelper.PageInfo;
import com.liao.badminton.code.*;
import com.liao.badminton.dto.BoutStatDto;
import com.liao.badminton.dto.StatDto;
import com.liao.badminton.service.BoutStatService;
import com.liao.badminton.vo.BoutStatVo;
import com.liao.badminton.vo.RankStatVo;
import com.liao.badminton.vo.StatVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import com.liao.badminton.code.validation.Delete;
import com.liao.badminton.code.validation.Insert;
import com.liao.badminton.code.validation.Update;
import com.liao.badminton.code.validation.FindDetail;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Map;

/**
 * @author liaocheng
 * @date 2024-11-01
 * description:录入对局统计表
 */
@RestController
@RequestMapping(value = "/boutStat")
@PreAuthorize("@ss.hasPermission('boutStat')")//权限管理;
public class BoutStatController {

    //  private static  Logger logger= LoggerFactory.getLogger(BoutStatController.class);

    @Autowired
    private BoutStatService boutStatService;


    /**
     * 新增boutStat
     */
    @RequestMapping(value = "/add")
    @PreAuthorize("@ss.hasPermission('boutStat:add')")//权限管理;
    public ResponseRest<Long> add(@RequestBody @Validated(Insert.class) BoutStatDto boutStat) throws ProjectException {
        return boutStatService.saveBoutStat(boutStat);
    }

    /**
     * 批量删除
     */
    @RequestMapping(value = "/deletes")
    @PreAuthorize("@ss.hasPermission('boutStat:deletes')")//权限管理;
    public ResponseRest<Boolean> deletes(@RequestBody @Validated(Delete.class) BoutStatDto param) throws ProjectException {
        return boutStatService.deletesBoutStat(param);
    }

    /**
     * 修改boutStat
     */
    @RequestMapping(value = "/update")
    @PreAuthorize("@ss.hasPermission('boutStat:update')")//权限管理;
    public ResponseRest<Boolean> update(@RequestBody @Validated(Update.class) BoutStatDto param) throws ProjectException {
        return boutStatService.updateBoutStat(param);
    }

    /**
     * 查询详情
     *
     * @param param
     * @return
     * @throws ProjectException
     */
    @RequestMapping(value = "/findDetail")
    @PreAuthorize("@ss.hasPermission('BoutStat:findDetail')")//权限管理;
    public ResponseRest<BoutStatVo> findDetail(@RequestBody BoutStatDto param) throws ProjectException {
        return boutStatService.findDetail(param);
    }

    /**
     * 条件查询（查询某人某次录入的对局统计）
     * @param param
     * @return
     * @throws ProjectException
     */
    @RequestMapping(value = "/findByImportIdUserId")
    @PreAuthorize("@ss.hasPermission('BoutStat:findByImportIdUserId')")//权限管理;
    public ResponseRest<BoutStatVo> findByImportIdUserId(@RequestBody BoutStatDto param) throws ProjectException {
        return boutStatService.findByImportIdUserId(param);
    }

    /**
     * 分页查询列表
     */
    @RequestMapping(value = "/list")
    @PreAuthorize("@ss.hasPermission('boutStat:list')")//权限管理;
    public ResponseRest<PageInfo<BoutStatVo>> list(@RequestBody PageParam<BoutStatDto> body) throws ProjectException {
        return boutStatService.findBoutStatByPageParam(body);
    }

    /**
     * (争对某群的带时间段的)个人战绩查询
     *
     * @param param
     * @return
     * @throws ProjectException
     */
    @RequestMapping(value = "/personalStat")
    @PreAuthorize("@ss.hasPermission('boutStat:personalStat')")//权限管理;
    public ResponseRest<StatVo> personalStat(@RequestBody StatDto param) throws ProjectException {
        return boutStatService.personalStat(param);
    }

    /**
     * 榜单查询
     *
     * @param param
     * @return
     * @throws ProjectException
     */
    @RequestMapping(value = "/rankList")
    @PreAuthorize("@ss.hasPermission('boutStat:rankList')")//权限管理;
    public ResponseRest<RankStatVo> rankList(@RequestBody StatDto param) throws ProjectException {
        return boutStatService.rankList(param);
    }

}
